package ptkdemo.client;

import com.googlecode.gwtptk.client.PageOf;

import java.io.Serializable;

/**
 * UserFilter contains filter fields and page setup as well.
 *
 * @author Richard "Virgo" Richter (virgo47@gmail.com)
 */
public class UserFilter implements Serializable {
	private String name;
	private int pageSize = PageOf.NO_PAGING;
	private int page = PageOf.NO_PAGING;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public void clear() {
		name = null;
		page = PageOf.FIRST_PAGE;
	}

	public UserFilter withPageSize(int pageSize) {
		this.pageSize = pageSize;
		page = PageOf.FIRST_PAGE;
		return this;
	}

	public int getPageSize() {
		return pageSize;
	}

	public boolean isPaged() {
		return pageSize != PageOf.NO_PAGING;
	}

	public int getResultOffset() {
		return (page - 1) * pageSize;
	}
}
